stream=open(r'C:\Users\hp\Desktop\aa.txt')#默认rt读文本文档
c=stream.read()#读取
print(c)
result=stream.readable()#判断文件是否可读
print(result)
line=stream.readline()#必须第一次读文件才能用，一次读一行，循环可用
print(line)
print('**************')

#读图片用rb
stream=open(r'C:\Users\hp\Desktop\index.jpg','rb')
c=stream.read()
print(c)

stream=open(r'C:\Users\hp\Desktop\aa.txt','w')##覆盖写
s='yes,'
result=stream.write(s)#一行里接着写
print(result)
stream.writelines('qwert\n','asdf\n')#换行写
stream.close()

stream=open(r'C:\Users\hp\Desktop\aa.txt','a')##续写
s='yes,'
result=stream.write(s)
print(result)
stream.close()

#用with结构代替close
with open(r'C:\Users\hp\Desktop\aa.txt','rb') as stream:
    c=stream.read()
    with open(r'C:\Users\hp\Desktop\bb.txt','wb') as wstream:
        wstream.write(c)
print('复制完成')

